package com.heima.file;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.model.PutObjectResult;

import java.io.FileInputStream;
import java.io.FileNotFoundException;

public class testOss {
    public static void main(String[] args) throws FileNotFoundException {

        /**
         * LTAI5tM15eaSxRhBtTaZtTPT
         * FVlYAr3yegr8DiUL71XYN9GZJxsfN0
         */

        // Endpoint以杭州为例，其它Region请按实际情况填写。
        String endpoint = "http://oss-cn-shanghai.aliyuncs.com";
        // 阿里云主账号AccessKey拥有所有API的访问权限，风险很高。
        String accessKeyId = "LTAI5tM15eaSxRhBtTaZtTPT";
        String accessKeySecret = "FVlYAr3yegr8DiUL71XYN9GZJxsfN0";

        // 创建OSSClient实例。
        OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);

        // 上传Byte数组。
        FileInputStream inputStream = new FileInputStream("C:/Users/CXH/Pictures/Saved Pictures/QQ图片20171213130128.jpg");
        PutObjectResult result = ossClient.putObject("leadnews-cxh", "material/a.jpg", inputStream);
        System.out.println("result = " + result);

        // 关闭OSSClient。
        ossClient.shutdown();
    }
}
